import { Schema } from 'mongoose';
import { ITaskMetadata } from '../types/ITaskMetadata';

export const TaskMetadataSchema = new Schema<ITaskMetadata>({
  sessionId: { type: String, required: true, index: true },
  metadataType: {
    type: String,
    enum: ['performance', 'analytics', 'user_behavior', 'system'],
    required: true,
    index: true
  },
  data: { type: Schema.Types.Mixed, required: true },
  version: { type: String, required: true },
  source: { type: String, required: true },
  reliability: { type: Number, min: 0, max: 1, default: 1 },
  expiresAt: { type: Date, sparse: true, index: { expireAfterSeconds: 0 } }
}, {
  timestamps: true,
  collection: 'task_metadata'
});

// Compound Indexes
TaskMetadataSchema.index({ sessionId: 1, metadataType: 1 });
TaskMetadataSchema.index({ metadataType: 1, createdAt: -1 });
TaskMetadataSchema.index({ source: 1, reliability: -1 });
